<template>
  <div style="margin-top:30px">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-row>
        <el-col :span="20">
          <div class="grid-content bg-purple">
            <el-form-item label="员工积分" style="margin-right:15px" label-width="100px" prop="availablePoints">
              <el-input v-model="form.availablePoints" :disabled="true" style="width:100%"/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <div class="grid-content bg-purple">
            <el-form-item label="商品名称" prop="name" style="margin-right:15px" label-width="100px">
              <el-select v-model="form.name" filterable placeholder="请选择"  style="width:100%" @change="nameChange($event)">
                <el-option
                  v-for="item in shopList"
                  :key="item.code"
                  :label="item.name"
                  :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <div class="grid-content bg-purple">
            <el-form-item label="消耗积分" prop="points" style="margin-right:15px" label-width="100px">
              <el-input v-model="form.points"  :disabled="true"/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="funcSubmit" :disabled="isDisable" plain>确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
import {pointsExchange, pointsExchangeList} from "@/api/integralManage/employeesIntegral"

Vue.use(VXETable)
export default {
  props:{
    operationCode:{
      type: Number,
      required: true
    },
    auditEdit:{
      type: String,
      required: true
    },
  },
  data() {
    return {
      isDisable:false,   //确定键显示按钮
      form: {
        availablePoints: this.operationCode,
        partyCode: this.auditEdit,
        code:''
      },
      shopList: [],
      rules: {
        availablePoints: [
          { required: true, message: '员工积分', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请选择商品名称', trigger: 'change' }
        ],
        points: [
          { required: true, message: '消耗积分', trigger: 'blur' }
        ]
      },
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    // 获取兑换商品信息
    getInfo() {
      pointsExchangeList().then(response => {
        this.shopList = response.data
      })
    },
    // 商品选择获取积分
    nameChange(e) {
      this.form.name = e.name
      this.form.points = e.points
      this.form.code = e.code
    },
    // 提交
    funcSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          const data = this.form
          this.isDisable = true
          pointsExchange(this.auditEdit,this.form.code)
            .then(response => {
              this.$message({message: response.msg, type: 'success'})
              this.$emit('fatherEditMethod')
            }).finally(() => {
            this.isDisable = false
          })
        } else {
          return false
        }
      })
    }
  },
}
</script>
<style lang="scss" scoped>
.dialog-footer {
  margin: 15px 0 15px 0;
  width: 90px;
  float: right;
}
.el-select-dropdown__item.selected {
  color: #606266;
  font-weight: 400;
}
</style>
